package com.shop.admin.dao.admin;


import com.shop.admin.reqeust.admin.AdminPageReq;
import com.shop.domain.admin.Admin;
import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.web.context.WebContext;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

@Repository
public class AdminSQLDao extends BaseSQLDao {

    /**
     * 分页查询管理员列表
     *
     * @param adminPageReq
     * @return
     */
    public Page<Admin> page(AdminPageReq adminPageReq) {
        String field = "*";
        String from = "t_admin a";
        String order = "a.create_time desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field, from, order);
        qs.addWhereWithoutParams("a.is_deleted = 0");
        qs.addWhereDateGtNotBlank("a.create_time", adminPageReq.getBeginCreateDate());
        qs.addWhereDateLtNotBlank("a.create_time", adminPageReq.getEndCreateDate());
        qs.addWhereLikeNotBlank("a.name", adminPageReq.getName());
        return this.page(qs, Admin.class);
    }


}
